package com.pucong.gitee.database.backup.business.database.controller;

import com.pucong.gitee.database.backup.business.database.service.OperationDataSqlService;
import com.pucong.gitee.database.backup.common.entity.database.dto.DatabaseDto;
import com.pucong.gitee.database.backup.common.entity.database.vo.ExeSqlResult;
import com.pucong.gitee.database.backup.utils.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author pucong
 * @url https://gitee.com/pucong
 * @create 2020-06-23
 */
@RestController
@RequestMapping("/operation/dataSql")
@Api(value = "sql操作-API ", tags = "6. sql操作 API")
public class OperationDataSqlController {

    @Autowired
    private OperationDataSqlService operationDataSqlService;

    @PostMapping("/executeSql/{databaseId}")
    @ApiOperation(value = "601根据数据库id,执行sql")
    public Res<ExeSqlResult> executeSql(@ApiParam("数据库id")@PathVariable("databaseId") String databaseId, @RequestBody DatabaseDto databaseDto){
        ExeSqlResult databaseTableList = operationDataSqlService.executeSql(databaseId, databaseDto);
        return Res.ok(databaseTableList);
    }

    @PostMapping("/autoTransactionalCommit/{databaseId}")
    @ApiOperation(value = "602处理事物开启、关闭、提交")
    public Res<Boolean> autoTransactionalCommit(@ApiParam("数据库id")@PathVariable("databaseId") String databaseId,@RequestBody DatabaseDto databaseDto){
        Boolean aBoolean = operationDataSqlService.autoTransactionalCommit(databaseId, databaseDto);
        return Res.ok(aBoolean);
    }
}
